<template>
  <div class="home">
    <h1>Home</h1>
  </div>
</template>

<script>
function http (url, opts) {
  return fetch(url, opts).then(res => {
    try {
      return res.json()
    } catch (error) {
      return res.text()
    }
  })
}
['get', 'post'].forEach(method => {
  http[method] = function (url, params) {
    return http(url, Object.assign({method}, params))
  }
})

export default {
  name: 'Home',
  mounted () {
    console.log('mounted')
    http.get('/test/test.json').then(res => {
      console.log(res)
    })
    http.get('/api/test.json').then(res => {
      console.log(res)
    })
    http.post('/api/test.json').then(res => {
      console.log(res)
    })
  }
}
</script>
